{{include file="header.html"}}
{{include file="{{$smarty.const.PLUG}}mobiscroll-city/mobiscroll.html"}}
	<div class="header loginhead">
		<div class="nav">
		    <div class="search return"><a href="javascript:history.go(-1);"></a></div>
		    <div class="title">填写收货地址</div>
		    <div class="right">
		        <a href="javascript:" id='submit_btn'>保存</a>
		    </div>
		</div>
	</div>
	<div class="container">
		<form class="form" name="form" method="post">
		<input name='id' type='hidden' value='{{$result.id}}'>
		<input id='region_ids' name='region_ids' type='hidden' value='{{$result.region_ids}}'>
			<div class="address">
				<div class="loginbox ad_border">
					<div class="login_wrap">
						<span class="icon">
							收&nbsp;&nbsp;货&nbsp;&nbsp;人
						</span>
						<div class="input_text">
							<input type="text" placeholder="请填写真实姓名，否则将无法进行配送" id="name" name="name" value="{{$result.name}}" maxlength="30" >
						</div>
					</div>
					<div class="login_wrap">
						<span class="icon">
							手机号码
						</span>
						<div class="input_text">
							<input type="tel" placeholder="请输入手机号码" id="tel" name="tel" value="{{$result.tel}}" maxlength="30" >
						</div>
					</div>
					<div class="login_wrap">
						<span class="icon">
							所在区域
						</span>
						<div class="input_text">
							<input id="region" placeholder="请选择所在地区" areaid="{{$result.region_ids}}" readonly="" class="" name='region' value="{{$result.region}}">
						</div>
					</div>
					
					<div class="login_wrap">
						<span class="icon">
							详细地址
						</span>
						<div class="input_text">
							<input type="text" placeholder="3-30个字，不包含特殊符号" id="address" name="address" value="{{$result.address}}" maxlength="100" >
						</div>
					</div>
					<div class="login_wrap">
						<span class="icon">
							邮政编码
						</span>
						<div class="input_text">
							<input type="number" placeholder="请填写邮编（选填）" id="number" name="zipcode" value="{{$result.zipcode}}"  maxlength="8">
						</div>
					</div>
				</div>
			</div>
			<div class="address">
				<div class="loginbox">		
					<div class="login_wrap default">
						<span class="icon">
							设为默认地址
						</span>
						<div class="input_text">
							<input type="checkbox" id="default"  name="hot" value='1' {{if $result.hot == '1'}}checked{{/if}}>
							<label for="default"></label>
						</div>

					</div>	

				</div>
			</div>
		</form>	
	</div>
	
<script>
	$(function(){
		// $('#province_id').change(function(){
		// 	getChild($('#province_id').val(),1,null);
		// });
		// $('#city_id').change(function(){
		// 	getChild($('#city_id').val(),2,null);
		// });
		$('#submit_btn').click(function(){
			$('#region_ids').val($('#region').attr('areaid'))
			var post_data = $("form.form").serialize();
			$.post('{{"index.php?app=address&act=save"|URL}}',post_data,function(xml){
				if(xml.statusCode == '200'){
					ui.success("收货地址已保存!");
					if($.cookie('history_url')){
	        			var history_url = $.cookie('history_url');
	        			$.cookie('history_url','',{expires: null,path: "/"});
	        			document.location.href=history_url;
	        		}else
						location.href='{{"index.php?app=address"|URL}}';
				}else{
					ui.alert(xml.message);
				}
			},'json');
		});
	});
	

	
	function getChild(id,type,current){
		$.post('{{"index.php?app=address&act=getChildAddress"|URL}}',{id:id,type:type,current:current},function(xml){
			switch(type){
				case 1 : 
					$('#area_id').html("<option value=''>请选择地区...</option>");
					var html = "<option value=''>请选择城市...</option>";
					$.each(xml, function(i,val){      
						html += "<option value='"+val.city_id+"'>"+val.city_name+"</option>";
					  });
					$('#city_id').html(html);
					break;
				case 2 : 
					var html = "<option value=''>请选择地区...</option>";
					$.each(xml, function(i,val){      
						html += "<option value='"+val.area_id+"'>"+val.area_name+"</option>";
					  });
					$('#area_id').html(html);
					break;
			}
			
		},'json');
	}
</script>
<script>
	var valo = $("#region").attr("areaid");
	$('#region').scroller('destroy').scroller({ preset: 'area', theme: 'android-ics light', display: 'bottom',valueo:valo });

	
</script>
{{include file="footer.html"}}